<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
	<%@ include file="/main/main_css.jsp" %>
    <%@ include file="/main/main_js.jsp" %>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>扫描二维码</title>
    
    <script src="JS/Camera.js"></script>
    <script src="JS/main.js"></script>

  </head>
  
  <body onbeforeunload="closeCamera();" onselectstart="return false">
    <!--  -->
    <div class="all-wrapper">
        <div class="row com-header text-center">
            <span>鹰潭市行政服务中心</span>
        </div>
        <div class="row main-content take-photos">
            <div class="col-md-24" >
                <div class="time-count pull-right">
                    <span>剩余</span>
                    <span id="time" class="text-red"></span>
                    <span>秒</span>
                </div>
            </div>
            <div class="col-md-24">
                <h1>二维码</h1>
            </div>
            <div class="col-md-24 card-wp">
                <div class="card-com">
                    <span class="tip">请将二维码置于二维码扫描区（如图所示）</span>
                    <div class="image-wrapper">
                        <img src="static\image\cards\card.png" alt="">
                    </div>
                </div>
            </div>
        </div>
        <div class="row footer">
            <a class="btn btn-success btn-lg" href="loginOut" role="button"><i class="fa fa-reply"></i>返回首页</a>
        </div>
        <form id="qrCodeScan" action="" method="post">
        	<input type="hidden" id="data" name="data"/>
        </form>
	    <form id="loginOut" action="loginOut"></form>
        <script>
        function onPageLoad(){
	    	countdown();
        	qrCodeScan();
        }
        var count = 14;
    	function countdown(){
    		$("#time").text(count);
    		if(count > 0){
    			window.setTimeout("countdown()",1000);
    			count --;
    		}else{
    			//关闭硬件
    			closeCamera();
    			//跳转到首页
    			$("#loginOut").submit();
    		}
    	}
    	
    	//语音提示
    	function soundIdCard(){
    		sound_speak("请将二维码置于识别区");
    	}
    	
    	//开启扫描二维码硬件
    	function qrCodeScan() {
    		var obj={"openType": 5,"layoutX": 410,"layoutY": 320,"layoutWidth": 620,"layoutHeight": 400,"choiceCamera":1};
    		var data=JSON.stringify(obj);
    	    send_command(
    	        "scanQR",
    	        data,
    	        function (json) {
    	        	var qrData = JSON.parse(json);
		            if (qrData.status == 100) {
		            	var qrInfo = qrData.imgStr;
		            	var qrDataJson = JSON.parse(qrInfo.replace(/'/g,"\""));
		            	var type = qrDataJson.type;
		            	//判断跳转地址
		            	if(type == "1"){
		            		$("#qrCodeScan").attr("action","getMyAppointmentById");
		            	}else if(type="2"){
		            		$("#qrCodeScan").attr("action","MyBussinessController/getBusinessInfo");
		            	}
		            	var ret = {
	            				"data":qrDataJson.data
	            		};
	            		$("#data").val(JSON.stringify(ret));
		                $("#qrCodeScan").submit();
		            } else {
		            	layer.alert("操作失败",function(){
			            	//跳转到首页
			    			$("#loginOut").submit();
		            	});
		            	closeCamera();
		            }
    	        });
    	}
    	
    	function closeCamera() {
    		window.external.Close_Camera("");
    	}
    	onPageLoad();
    	var winH = $(document).height();
        var mainH = winH -160;
        $('.main-content').height(mainH);
        </script>
  </body>
</html>
